import java.util.ArrayList;



public class Main {

	public static void main(String[] args) {
		
		String filename = "machines.txt";
		ArrayList<String> data = (new FileRead(filename)).getLines();
		ArrayList<MachineData> mData = new ArrayList<MachineData>();
		Global.demo = false;
		
		for(String s: data) {
			mData.add(new MachineData(s));
		}
		
		Machine[] machines = new Machine[Global.numMachines];
		
		for(int i = 0; i < machines.length; i++) {
			machines[i] = new Machine(mData, i);
		}
		
		for(int i = 0; i < machines.length; i++) {
			machines[i].start();
		}
		
		long t = System.currentTimeMillis();
		long finish = t + Global.simLength;
		
		while(true) {
			t = System.currentTimeMillis();
			
			if (t >= finish) {
				System.out.println("Total messages and bandwidth (bytes) : " + Global.numMessages);
				System.out.println("Total messages per second per processor : " + (Global.numMessages / (float) Global.numMachines) / (Global.simLength/1000));
				System.out.println("Total bandwith per processor : " + (Global.numMessages / (float) Global.numMachines) / (Global.simLength/1000));
				System.out.println("Total number of failures : " + Global.numFailures);
				System.exit(0);
			}
		}
	}
	
}
